import RequestHttp from '../request';

// 分页
    // 便签分页传入的参数类型
    export interface NodeQuery {
        page: number, size: number
    }
    export interface Node {
        status: number;
        message: string
        data:Array<NodeData>
    }
    export interface Todo {
        status: number;
        message: string
        data:Array<NodeTodo>
    }
    // node列表成功后返回的参数类型
    export interface NodeData {
        _id?:string;
        dates:string;
        content:string;
    }
    // todo列表成功后返回的参数类型
     export interface NodeTodo {
                _id?:string;
                isdone:boolean;
                content:string;
            }
    
export const getNode:any = (data: NodeQuery) => {
    return RequestHttp.get<Array<NodeData>>(`/note/page/${data.page}/${data.size}`);
}
export const getTodo:any = (data: NodeQuery) => {
    return RequestHttp.get<Array<NodeTodo>>(`/todo/${data.page}/${data.size}`);
}

// 返回的详情类型
export interface NodeOrTodo {
    status: number;
    message: string
    data:Add
}
export const getDetail:any = (id:string) => {
    return RequestHttp.get<NodeData>(`/note/id/${id}`);
}
export const getTodoDetail:any = (id:string) => {
    return RequestHttp.get<NodeTodo>(`/todo/id/${id}`);
}

// 新增node
        export interface NodeAdd {
            dates:string;
            content:string;
        }
        export interface Add {
            dates?:string;
            _id?:string;
            isdone?:boolean;
            content?:string;
        }

export const nodeAdd:any = (data:NodeAdd) => {
    return RequestHttp.post<NodeData>(`/note`,data);
}

// 新增todo
export interface TodoAdd {
    _id?: string;
    isdone: boolean;
    content: string;
}
export const todoAdd:any = (data:TodoAdd) => {
    return RequestHttp.post<NodeTodo>(`/todo`,data);
}
// 修改node
export const nodeChange:any = (data:NodeData,id:string) => {
    return RequestHttp.put<NodeData>(`/note/${id}`,data);
}
// 修改todo
export const todoChange:any = (data:NodeTodo,id:string) => {
    return RequestHttp.put<NodeTodo>(`/todo/${id}`,data);
}
// 删除node
export const nodeDelelte:any = (id:string) => {
    return RequestHttp.delete<NodeData>(`/note/${id}`);
}
// 删除todo
export const todoDelelte:any = (id:string) => {
    return RequestHttp.delete<NodeTodo>(`/todo/${id}`);
}
